package com.ruoyi.education.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.education.domain.StudentRepeater;
import com.ruoyi.education.service.IStudentRepeaterService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 留级学生Controller
 * 
 * @author ruoyi
 * @date 2022-12-26
 */
@RestController
@RequestMapping("/repeater")
public class StudentRepeaterController extends BaseController
{
    @Autowired
    private IStudentRepeaterService studentRepeaterService;

    /**
     * 查询留级学生列表
     */
    @RequiresPermissions("education:repeater:list")
    @GetMapping("/list")
    public TableDataInfo list(StudentRepeater studentRepeater)
    {
        startPage();
        List<StudentRepeater> list = studentRepeaterService.selectStudentRepeaterList(studentRepeater);
        return getDataTable(list);
    }

    /**
     * 导出留级学生列表
     */
    @RequiresPermissions("education:repeater:export")
    @Log(title = "留级学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentRepeater studentRepeater)
    {
        List<StudentRepeater> list = studentRepeaterService.selectStudentRepeaterList(studentRepeater);
        ExcelUtil<StudentRepeater> util = new ExcelUtil<StudentRepeater>(StudentRepeater.class);
        util.exportExcel(response, list, "留级学生数据");
    }

    /**
     * 获取留级学生详细信息
     */
    @RequiresPermissions("education:repeater:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(studentRepeaterService.selectStudentRepeaterById(id));
    }

    /**
     * 新增留级学生
     */
    @RequiresPermissions("education:repeater:add")
    @Log(title = "留级学生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentRepeater studentRepeater)
    {
        return toAjax(studentRepeaterService.insertStudentRepeater(studentRepeater));
    }

    /**
     * 修改留级学生
     */
    @RequiresPermissions("education:repeater:edit")
    @Log(title = "留级学生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentRepeater studentRepeater)
    {
        return toAjax(studentRepeaterService.updateStudentRepeater(studentRepeater));
    }

    /**
     * 删除留级学生
     */
    @RequiresPermissions("education:repeater:remove")
    @Log(title = "留级学生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(studentRepeaterService.deleteStudentRepeaterByIds(ids));
    }
}
